package com.example.task01_servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "CookieServlet", urlPatterns="/cookie")
public class CookieServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.测试一下浏览器的请求是否到达
        System.out.println("看看有没有执行到这里哦!");
        //2.创建Cookie对象并添加到响应信息中
        Cookie cookie=new Cookie("name","zhangfei");
        response.addCookie(cookie);
        System.out.println("创建Cookie成功!");
    }
}
